<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%  
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<meta name="format-detection" content="telephone=no">
	<meta content="telephone=no" name="format-detection">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<link href="<%=basePath %>resources/assets/stylesheets/main.css" rel="stylesheet" type="text/css" />
	<title>登录</title>
</head>
<body>
	<div class="html register" id="J_html">
		<p class="top"><img src="<%=basePath %>resources/assets/img/icon.jpeg" class="top-i"></p>
		<p class="til">会员登录</p>
		<div class="form">
			<div
					class="line" hidden="hidden"><input type="text" class="ctrol" data-key="recommendUserId"
										name="recommendUserId" id="recommendUserId" th:value="${recommendUserId}"></div>
			<div
					class="line"><input type="text" placeholder="请输入手机号" class="ctrol" data-key="mobile"
										name="mobile" id="mobile"></div>
			<div
					class="line"><input type="password" placeholder="请输入密码" class="ctrol" data-key="password"
										name="password" id="password"></div>

			<p class="btnline"><button class="btn" id="J_btn">登录</button></p>
		</div>
	</div>
	<script language="javascript" type="text/javascript" src="<%=basePath %>resources/assets/javascript/jquery-2.1.4.min.js"></script>
	<script language="javascript" type="text/javascript" src="<%=basePath %>resources/assets/javascript/func.js"></script>
	<script type="text/javascript">
        var wtype = window.innerWidth<1000?'wap':'pc';
        var uri = "${uri}";
		function errormsg(elm,msg){
            if(wtype=='wap'){
                CUES.tip({"msg":msg,"type":"danger"});
            }else{
                var dom = $('<span class="errormsg">'+msg+'</span>');
                elm.addClass('ctrol_error');
                elm.after(dom);
                setTimeout(function(){
                    dom.fadeOut();
                    setTimeout(function(){
                        dom.remove();
                    },1000);
                    elm.removeClass('ctrol_error');
                },2500);
            };
        };
		$(function(){
			var data = {},
				isajax = false;

			$('.ctrol').blur(function(){
				var self = $(this),
					v = self.val().trim(),
					k = self.attr('data-key');

				if(k == 'phone'){
					if(!/^[1][0-9]{10}$/ig.test(v)){
						self.val('')
						return;
					};
				};
				data[k] = v;
			});

            $('#J_btn').click(function(){
                if(isajax) return;
                $(".line>.ctrol").each(function (index,line) {
                    data[$(line).data('key')] = $(line).val();
                })

                if(!/^[1][0-9]{10}$/ig.test(data.mobile)){
                    errormsg($("#mobile"),'请输入手机号');
                    return;
                };
                if(!data.password){
                    errormsg($("#password"),'请输入密码');
                    return;
                };
                isajax = true;
                $('#J_btn').html('正在提交···');
                data['role'] = 1;
                data['source'] = 5;
                $.ajax({
                    type: "POST",
                    url: "<%=basePath %>account/login",
                    contentType: "application/json",
                    data: JSON.stringify(data),
                    dataType: "json",
                    success: function(res){
                        if(res.status==0){
                        	   if(uri != ''){
                        		   window.location.href = "<%=basePath%>"+uri;
                        	   }else{
                        		   window.location.reload();
                        	   }
                        }else {
                            errormsg($("#mobile"),res.message);
                        }
                    },
                    complete:function(){
                        isajax = false;
                        $('#J_btn').html('提交')
                    }
                });
            });
		});
	</script>
</body>
</html>
